import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:robotcontrol/entity/common_item.dart';
import 'package:robotcontrol/utils/cache_image.dart';

class VideoItemWidget extends StatelessWidget {
  final Data data; //  // 路径：common_item包
//点击回调方法
  final VoidCallback callBack;

  //是否开启Hero动画
  final bool openHero;
  final Color titleColor;
  final Color categoryColor;

  const VideoItemWidget({Key key,
    this.data,
    this.callBack,
    this.titleColor = Colors.white,
    this.categoryColor = Colors.white,
    this.openHero = false})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: (){
        callBack();
      },
      child: Container(
        padding: EdgeInsets.fromLTRB(10, 10, 10, 5),
        child: Row(
          children: [
            //左边图片显示
            _videoImage(),
            //右边文字显示
            _videoText()
          ],
        ),
      ),
    );
  }
   //左边图片显示
  Widget _videoImage(){
    return Stack(
      children: [
        //图片
        ClipRRect(
          borderRadius: BorderRadius.circular(5),
          child: _coverWidget(),
        )
      ],
    );
  }
  //右边文字显示
  Widget _videoText(){
    return Expanded(flex:1,
        child: Padding(
          padding: EdgeInsets.all(10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(data.title,
              style: TextStyle(color: titleColor,fontSize: 14,fontWeight: FontWeight.bold),
              ),
              Padding(padding: EdgeInsets.only(top: 15),
                child:Text('#${data.category} / ${data.author?.name}',style: TextStyle(color: categoryColor,fontSize: 12),) ,
              )
            ],
          ),
        ));
  }
  Widget _coverWidget(){
    if(openHero){
      return Hero(tag: '${data.id}${data.time}', child: _imageWidget());
    }else{
      return _imageWidget();
    }
  }
  Widget _imageWidget(){
    return cacheImage(
      data.cover.detail,
      width: 135,
      height :80
    );
  }
}